package com.leenmvc.core.web.controller;

import com.leenmvc.core.annotation.Note;
import com.leenmvc.core.base.BaseController;
import com.leenmvc.core.security.dao.core.SysRolePermissionDao;
import com.leenmvc.core.security.entity.core.SysPermission;
import com.leenmvc.core.base.result.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @program: financial_management
 * @description: 角色权限表
 * @author: Cloud
 * @create: 2020/7/8 15:57:00
 */
@RestController
@RequestMapping("system/sysPermission")
public class SysPermissionController extends BaseController<SysPermission> {

    @Autowired
    private SysRolePermissionDao sysRolePermissionDao;

    @Note("获取未绑定的角色权限")
    @GetMapping("getPermission")
    public Result getUnboundPermission(String roleId){
        HashMap<Object, Object> map = new HashMap<>();
        map.put("roleId",roleId);
        List<SysPermission> all = getAll();
        List<Long> permList = sysRolePermissionDao.listBySqlKey("getPermListByRoleId", map);
        List<SysPermission> sysPermissions = all.stream().filter(SysPermission -> !permList.contains(SysPermission.getId())).collect(Collectors.toList());
        return new Result().ok(sysPermissions);
    }
}
